package jp.yvn.game.shooting.element;

import jp.yvn.game.shooting.util.Const;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.PointF;

/**
 * 弾幕オブジェクトクラス
 * 
 * @author Yvn_pq
 */
public class CircleBulletEntity extends BaseBulletEntity {

	private final static int MIN_CIRCLE = 4; // 最少弾幕数

	private final float mBuletSpeed = 1.0f;

	protected double angle = 0;

	protected int childBulletNumber = 0;

	protected final PointF[] childBulletPoint;

	/**
	 * コンストラクタ
	 * 
	 * @param centerX
	 * @param centerY
	 * @param viewSize
	 * @param number
	 */
	public CircleBulletEntity(float centerX, float centerY, Point viewSize, int number) {
		super(viewSize);
		childBulletNumber = number;
		if (childBulletNumber < MIN_CIRCLE) {
			childBulletNumber = MIN_CIRCLE;
		}
		childBulletPoint = new PointF[childBulletNumber];
		angle = Math.PI * 2 / childBulletNumber;
		for (int i = 0; i < childBulletNumber; i++) {
			childBulletPoint[i] = new PointF(centerX, centerY);
		}
	}

	/**
	 * 描画します
	 * 
	 * @param canvas
	 */
	@Override
	public void draw(Canvas canvas, Bitmap bulletImg) {
		for (int i = 0; i < childBulletNumber; i++) {
			canvas.drawBitmap(bulletImg, childBulletPoint[i].x - Const.BULLET_BLUE_HALF_SIZE, childBulletPoint[i].y - Const.BULLET_BLUE_HALF_SIZE, null);
		}
		// アニメーション更新
		setAnimation();
	}

	/**
	 * 座標がオブジェクトが画面の外かどうか
	 * 
	 * @return boolean
	 */
	@Override
	public boolean isOutsideView() {
		return false;
	}

	/**
	 * アニメーションを設定します
	 */
	@Override
	public void setAnimation() {
		for (int i = 0; i < childBulletNumber; i++) {
			childBulletPoint[i].x += mBuletSpeed * Math.cos(i * angle);
			childBulletPoint[i].y -= mBuletSpeed * Math.sin(i * angle);
		}
	}
}
